package com.yhj.reggie.mapper;

import com.yhj.reggie.dto.DishDto;
import com.yhj.reggie.entity.Dish;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DishMapper {

    //根据类品id找数量
    @Select("select count(*) from dish where category_id=#{categoryId} and is_deleted=0")
    Integer countByCid(Long categoryId);


    //添加菜品
    @Insert("insert into dish values (null,#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    Integer save(DishDto dishDto);


    //分页查菜品,模糊查询菜名(动态sql语句)d
    List<Dish> findAll1(@Param("name") String name);

    //分页查询连表,查菜品
    List<DishDto> findAll2(@Param("name") String name);

    //回显菜品
    DishDto findById(Long id);

    //修改菜品
    Integer update(DishDto dishDto);

    //根据类别id(category)找菜品
    @Select("select * from dish " +
            "where category_id=#{categoryId} and is_deleted=0 and status=#{status} " +
            "order by sort asc ")
    List<Dish> findByCid(@Param("categoryId") Long categoryId, @Param("status") Integer status);
}
